package com.augmentum.login;

import java.util.HashMap;
import java.util.Map;

import com.augmentum.login.model.User;

public class AppContent {

    private static ThreadLocal<AppContent> local = new ThreadLocal<AppContent>();
    private final Map<String, Object> objects = new HashMap<String, Object>();
    private static String contentPath;

    public AppContent() {
        // empty
    }

    public User getUser() {
        return (User) objects.get(Constants.USER);
    }

    public void setUser(User user) {
        objects.put(Constants.USER, user);
    }

    public static void setContentPath(String contentPath) {
        AppContent.contentPath = contentPath;
    }

    public static String getContentPath() {
        return contentPath;
    }

    public Map<String, Object> getObjects() {
        return objects;
    }

    public Object getSession() {
        return  objects.get(Constants.SESSION);
    }

    public void addObject(String key, Object value) {
        objects.put(key, value);
    }

    public Object getObject(String key) {
        return objects.get(key);
    }

    public void clearMap() {
        AppContent context = local.get();
        if (context != null) {
            context.objects.clear();
        }
        context = null;
    }

    public void removeObject(String key) {
        objects.remove(key);
    }

    public static AppContent getAppContent() {
        AppContent appContent = local.get();
        if (appContent == null) {
            appContent = new AppContent();
            local.set(appContent);
        }
        return appContent;
    }
}
